* Table 6
 
use "temp/EIA_clean.dta", clear
keep if year==1994
gen sales_norm = salestot / totalsales // normalize by total sales
gen lsales = log(sales_norm)
egen p10 = pctile(lsales), p(10)
egen p25 = pctile(lsales), p(25)
egen p50 = pctile(lsales), p(50)
egen p75 = pctile(lsales), p(75)
egen p90 = pctile(lsales), p(90)
egen p95 = pctile(lsales), p(95)
preserve
	collapse p10 p25 p50 p75 p90 p95
	label var p10 "10th pctile sales"
	label var p25 "25th pctile sales"
	label var p50 "50th pctile sales"
	label var p75 "75th pctile sales"
	label var p90 "90th pctile sales"
	label var p95 "95th pctile sales"
	export excel "../../Output/Table6_Data", first(varl) sh("Percentiles of Log sales shares") replace
restore

* Importers
preserve
	keep if importer==1
	egen sip10 = pctile(si*100), p(10)
	egen sip25 = pctile(si*100), p(25)
	egen sip50 = pctile(si*100), p(50)
	egen sip75 = pctile(si*100), p(75)
	egen sip90 = pctile(si*100), p(90)
	egen sip95 = pctile(si*100), p(95)
	collapse sip10 sip25 sip50 sip75 sip90 sip95 
	label var sip10 "10th pctile si"
	label var sip25 "25th pctile si"
	label var sip50 "50th pctile si"
	label var sip75 "75th pctile si"
	label var sip90 "90th pctile si"
	label var sip95 "95th pctile si"
	export excel "../../Output/Table6_Data", first(varl) sh("Percentiles of Import Shares")
restore

*3. Exporters
preserve
	keep if exporter==1
	egen xip10 = pctile(xi*100), p(10)
	egen xip25 = pctile(xi*100), p(25)
	egen xip50 = pctile(xi*100), p(50)
	egen xip75 = pctile(xi*100), p(75)
	egen xip90 = pctile(xi*100), p(90)
	egen xip95 = pctile(xi*100), p(95)
	collapse xip10 xip25 xip50 xip75 xip90 xip95
	label var xip10 "10th pctile sx"
	label var xip25 "25th pctile sx"
	label var xip50 "50th pctile sx"
	label var xip75 "75th pctile sx"
	label var xip90 "90th pctile sx"
	label var xip95 "95th pctile sx"
	export excel "../../Output/Table6_Data", first(varl) sh("Percentiles of Export Shares")
restore
